<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="top">
        Enter Inventory
    </ui:define>

    <ui:define name="left">
    </ui:define>



    <ui:define name="body">
        <h:form rendered="#{itemCTRL.doUpdate}" id="catList">
            <h:outputLabel value="Category: "/>
            <h:selectOneMenu id="category">
                <f:selectItem itemValue="-1" itemLabel=""/>
                <c:forEach items="#{categoryCTRL.categoryList}" var="items">
                    <f:selectItem itemValue="#{items.id}" itemLabel="#{items.level}#{items.name}"/>
                </c:forEach>
            </h:selectOneMenu>
            <h:commandLink value="Change" action="#{itemCTRL.changeCategory}"/>
            <br/>
        </h:form>
        <h:form id="inventoryEntryForm" enctype="multipart/form-data">
            <h:panelGrid columns="3" border="0">
                
                <h:outputLabel for="name" value="Name:"/>
                <h:inputText label="Name" id="name" value="#{itemCTRL.item.name}">
                    <f:validator validatorId="validators.generalLengthValidator"/>
                </h:inputText>
                <h:message showDetail="true" showSummary="false" for="name"/>
                
                <h:outputLabel for="manufacturer" value="Manufacturer:"/>
                <h:inputText label="Manufacturer" id="manufacturer" value="#{itemCTRL.item.manufacturer}">
                    <f:validator validatorId="validators.generalLengthValidator"/>
                </h:inputText>
                <h:message showDetail="true" showSummary="false" for="manufacturer"/>
                
                <h:outputLabel for="price" value="Price:"/>
                <h:inputText label="Price" id="price" value="#{itemCTRL.item.price}">
                    <f:convertNumber pattern="#.##" currencySymbol="$" type="currency"/>
                </h:inputText>
                <h:message showDetail="true" showSummary="false" for="price"/>
                
                <h:outputLabel for="descrip" value="Description:"/>
                <h:inputTextarea label="Description" id="descrip" value="#{itemCTRL.item.descrip}">
                    <f:validator validatorId="validators.descriptionValidator"/>
                </h:inputTextarea>
                <h:message showDetail="true" showSummary="false" for="descrip"/>
                
                <c:choose>
                    <c:when test="#{itemCTRL.doUpdate}">
                        <c:forEach items="#{itemCTRL.item.attributeValues}" var="items">
                            <h:outputLabel value="${items.attribute.name}"/>
                            <h:inputText label="${items.attribute.name}" id="attribute${items.attribute.id}" value="#{items.value}">
                                <f:validator validatorId="validators.generalLengthValidator"/>
                            </h:inputText>
                            <h:message showDetail="true" showSummary="false" for="attribute${items.attribute.id}"/>
                        </c:forEach>
                    </c:when>
                    <c:otherwise>
                        <c:forEach items="#{itemCTRL.itemAttributes}" var="items">
                            <h:outputLabel value="${items.name}"/>
                            <h:inputText label="${items.name}" id="item${items.id}">
                                <f:validator validatorId="validators.generalLengthValidator"/>
                            </h:inputText>
                            <h:message showDetail="true" showSummary="false" for="item${items.id}"/>
                        </c:forEach>
                        <input type="file" id="imageFile" name="imageFile"/>
                    </c:otherwise>
                </c:choose>                
                
                <h:commandButton 
                    action="#{itemCTRL.enterInventory}" 
                    value="Submit"/>
                <h:panelGroup/>
                <h:panelGroup/>
            </h:panelGrid>
        </h:form>
    </ui:define>

</ui:composition>
